<?php
/**
 * Created by PhpStorm.
 * User: hepenghui
 * Date: 2018/6/13
 * Time: 上午11:22
 */

namespace common\models;

use Yii;

class AppUpdateConf extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%app_update_conf}}';
    }

    public static function getDb()
    {
        return Yii::$app->get('db');
    }

    public function getData()
    {
        $data   = self::find()->asArray()->all();
        return $data;
    }

    public function backendData()
    {
        $return = [];
        $data   = $this->getData();
        foreach ($data as $item)
        {
            $return[$item["name"]]  = unserialize($item["value"]);
        }
        return $return;
    }

    public function apiData()
    {
        $conf   = [];
        $list   = $this->getData();
        if(!empty($list))
        {
            foreach ($list as $item)
            {
                $data[$item["name"]]    = unserialize($item["value"]);
            }
            //各项配置
            $conf["account"]    = $data["account"];
            $conf["ios"]        = $data["ios"];
            $conf["android"]    = $data["android"];

            $conf["ios"]["update_info"]     = $data["other"]["update_info"];
            $conf["android"]["update_info"] = $data["other"]["update_info"];
        }
        return $conf;
    }
}